package com.htpay.model.eo;

/**
 * 动态充值、优惠折扣率
 * <p>
 * 列举枚举类
 * 最高优惠9.9
 */
public enum ChargeDiscount {

    DISCOUNT_100(100, 0.45),//100: 99.55
    DISCOUNT_200(200, 0.50),//200: 199.00
    DISCOUNT_300(300, 0.55),//300: 298.35
    DISCOUNT_400(400, 0.60),//400: 397.60
    DISCOUNT_500(500, 0.65);//500: 496.75


    /**
     * 优惠率折扣:
     * 1.price == 100: 0.5%;
     * 3.price between 200 ~ 500: 0.55%
     * 4.price > 500 & price < 1000: 0.55%
     */
    private double feeRate;

    /**
     * 充值金额：整数（100的整数倍)
     */
    private int chargeMoney;

    ChargeDiscount(int chargeMoney, double feeRate) {
        this.chargeMoney = chargeMoney;
        this.feeRate = feeRate;
    }

    /**
     * 获取真实充值金额
     *
     * @param chargeMoney
     * @return
     */
    public static double getRealMoney(double chargeMoney) {
        for (ChargeDiscount cd : ChargeDiscount.values()) {
            if (cd.chargeMoney == chargeMoney) {
                double feeRate = cd.feeRate;
                return chargeMoney * (1 - feeRate) / 100;
            }
        }

        //其他的金额直接返回减去4.5
        return chargeMoney - 4.5;
    }
}
